﻿using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Bio.Data.UnitTests
{
    /// <summary>
    ///This is a test class for BioExtensiblePropertyBaseTest and is intended
    ///to contain all BioExtensiblePropertyBaseTest Unit Tests
    ///</summary>
    [TestClass()]
    public class BioExtensiblePropertyBaseTest
    {
        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext { get; set; }

        /// <summary>
        ///A test for Item
        ///</summary>
        [TestMethod()]
        public void ItemTest()
        {
            string key = "ItemTest";
            BioExtensiblePropertyBase target = new BioExtensiblePropertyBase();

            Assert.AreEqual(null, target.ExtendedProperties[key]);

            target.SetExtendedProperty(key, 1);
            Assert.AreEqual(1, target.ExtendedProperties[key]);

            target.SetExtendedProperty(key, "Hello");
            Assert.AreEqual("Hello", target.ExtendedProperties[key]);

            target.ClearExtendedProperty(key);
            Assert.AreEqual(null, target.ExtendedProperties[key]);

            BioExtensiblePropertyBase.RegisterDefaultValue(key, typeof(BioExtensiblePropertyBase), "BaseValue");
            Assert.AreEqual("BaseValue", target.ExtendedProperties[key]);

            // Clear the value
            BioExtensiblePropertyBase.RegisterDefaultValue(key, typeof(BioExtensiblePropertyBase), null);
        }

        internal class BioPropertyTest : BioExtensiblePropertyBase {}

        /// <summary>
        ///A test for RegisterDefaultValue
        ///</summary>
        [TestMethod()]
        public void RegisterDefaultValueTest()
        {
            string key = "ItemTest";
            BioExtensiblePropertyBase target = new BioExtensiblePropertyBase();

            Assert.AreEqual(null, target.ExtendedProperties[key]);

            BioExtensiblePropertyBase.RegisterDefaultValue(key, typeof(BioExtensiblePropertyBase), "BaseValue");
            Assert.AreEqual(null, target.GetExtendedProperty<string>(key));
            Assert.AreEqual("BaseValue", target.ExtendedProperties[key]);
            Assert.AreEqual("BaseValue", BioExtensiblePropertyBase.GetDefaultValue(key, typeof(BioExtensiblePropertyBase), false));
            Assert.AreEqual(null, BioExtensiblePropertyBase.GetDefaultValue(key, typeof(object), false));
            Assert.AreEqual("BaseValue", BioExtensiblePropertyBase.GetDefaultValue(key, typeof(BioPropertyTest), true));

            target.SetExtendedProperty(key, "Hello");
            Assert.AreEqual("Hello", target.ExtendedProperties[key]);
            Assert.AreEqual("Hello", target.GetExtendedProperty<string>(key));
            Assert.AreEqual("BaseValue", BioExtensiblePropertyBase.GetDefaultValue(key, typeof(BioExtensiblePropertyBase), false));
            Assert.AreEqual(null, BioExtensiblePropertyBase.GetDefaultValue(key, typeof(object), false));
            Assert.AreEqual("BaseValue", BioExtensiblePropertyBase.GetDefaultValue(key, typeof(BioPropertyTest), true));

            target.SetExtendedProperty(key, null);
            Assert.AreEqual(null, target.ExtendedProperties[key]);

            target.ClearExtendedProperty(key);
            Assert.AreEqual("BaseValue", target.ExtendedProperties[key]);

            // Clear the value
            BioExtensiblePropertyBase.RegisterDefaultValue(key, typeof(BioExtensiblePropertyBase), null);
        }

        /// <summary>
        ///A test for DoesExtendedPropertyExist
        ///</summary>
        [TestMethod()]
        public void DoesExtendedPropertyExistTest()
        {
            string key = "ItemTest";
            BioExtensiblePropertyBase target = new BioExtensiblePropertyBase();

            Assert.AreEqual(false, target.DoesExtendedPropertyExist(key));
            target.SetExtendedProperty(key, "Hello");
            Assert.AreEqual(true, target.DoesExtendedPropertyExist(key));
            Assert.AreEqual(false, target.DoesExtendedPropertyExist("itemtest"));
            Assert.AreEqual(false, target.DoesExtendedPropertyExist("ITEMTEST"));
        }

        /// <summary>
        ///A test for ClearExtendedProperty
        ///</summary>
        [TestMethod()]
        public void ClearExtendedPropertyTest()
        {
            string key = "ItemTest";
            BioExtensiblePropertyBase target = new BioExtensiblePropertyBase();

            Assert.AreEqual(false, target.DoesExtendedPropertyExist(key));
            target.SetExtendedProperty(key, "Hello");
            Assert.AreEqual(true, target.DoesExtendedPropertyExist(key));

            target.ClearExtendedProperty(key);
            Assert.AreEqual(false, target.DoesExtendedPropertyExist(key));
            
            BioExtensiblePropertyBase.RegisterDefaultValue(key, typeof(BioExtensiblePropertyBase), "BaseValue");
            Assert.AreEqual(false, target.DoesExtendedPropertyExist(key));

            // Clear the value
            BioExtensiblePropertyBase.RegisterDefaultValue(key, typeof(BioExtensiblePropertyBase), null);
        }
    }
}
